package com.hongxin.nw.netty.utils.pools;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 设备编码对应心跳时间列表操作
 */
public class HeartBeatPools {
    //设备编号 对应 心跳时间
    private final static Map<String, Long> hb = new ConcurrentHashMap<>();
    public static Set<String> getSets(){
        return hb.keySet();
    }
    public static int getSize(){
        return hb.size();
    }
    public static Long getHB(final String code) throws Exception {
        if (hb.containsKey(code)) {
            return hb.get(code);
        }else{
            throw new Exception("设备心跳记录找不到,设备: " + code);
        }
    }
    public static void addHB(final String code, final Long data) {
        hb.put(code, data);
    }
    public static void removeHB(final String code) {
        if (hb.containsKey(code)){
            hb.remove(code);
        }
    }
}